using System.Collections;
using UnityEngine;

public static class TimerUtils
{
    // 每帧调用，返回剩余秒数（整数），为 0 时表示结束
    public static int Countdown(ref float timer, float duration, float deltaTime)
    {
        if (timer <= 0)
        {
            timer = duration;
        }

        timer -= deltaTime;

        return Mathf.Max(0, Mathf.CeilToInt(timer));
    }
}

public static class UIAnimations
{

    public static IEnumerator ScaleAnimRoutine(Transform target, bool isOpen, float duration)
    {
        if (isOpen) target.gameObject.SetActive(true);
        Vector3 start = isOpen ? Vector3.zero : Vector3.one / 2;  // 起点
        Vector3 end = isOpen ? Vector3.one / 2 : Vector3.zero;  // 终点

        float timer = 0f;
        while (timer < duration)
        {
            timer += Time.deltaTime;
            float t = timer / duration;
            target.localScale = Vector3.Lerp(start, end, t); // 插值过渡
            yield return null;
        }
        target.localScale = end; // 最终定格
        if (!isOpen) target.gameObject.SetActive(false);

    }
}